package com.ruoyi.project.relation.inittable;

import com.ruoyi.inittable.domain.TableColumnInfo;
import com.ruoyi.inittable.domain.TableIndexInfo;
import com.ruoyi.inittable.service.ITableBuildInfoService;
import org.shoukaiseki.ruoyi.annotation.TableBuild;

import java.util.List;

import static com.ruoyi.inittable.utils.TableColumnInfoBuilder.column;
import static com.ruoyi.inittable.utils.TableIndexInfoBuilder.index;
import static com.ruoyi.inittable.utils.TableInfoUtils.tableColumns;
import static com.ruoyi.inittable.utils.TableInfoUtils.tableIndexs;

@TableBuild(name = "business_link", comment = "业务链路",version = 1
        ,remark = "用于查询链路,同树结构祖代表"
//        ,primaryKey = "primary key (source_owner_id, source_owner_name, source_owner_type, ancestor_owner_id, ancestor_owner_name, ancestor_owner_type,link_type)"
)
public class BusinessLinkInitTableInfo implements ITableBuildInfoService {


    @Override
    public List<TableColumnInfo> tableColumnInfoList(){
        List<TableColumnInfo> table = tableColumns(
                //ownerName 还是与 tableName 相同好一点
                column("    business_link_id bigint(20) unsigned auto_increment comment '主键' ").primaryKey(),
                column("    source_owner_id         bigint(20) unsigned default 0                 not null comment '来源业务ID',"),
                column("    source_owner_name       varchar(64)         default ''                not null default '' comment '所属业务名称',"),
                column("    source_owner_type       varchar(64)         default ''                not null default '' comment '业务类型',")
                .description("inventory_bom 在多个业务中使用,类型去区分所属"),
                column("    ancestor_owner_id         bigint(20) unsigned default 0                 not null comment '祖级业务ID',"),
                column("    ancestor_owner_name       varchar(64)         default ''                not null default '' comment '祖级业务名称',"),
                column("    ancestor_owner_type       varchar(64)         default ''                not null default '' comment '祖级业务类型',"),
//                column("    type                int(12)         default '0'                not null default '' comment '链接类型',")
//                .description("存在多条链路时根据该字段区分"),
                column("    level       tinyint(8)         default '0'       not null  comment '级别',")
                .description("第一级为1,第二级为2,以此类推"),
                column("    self_link_flag       char(1)         default '0'               not null default '' comment '自链接标识',")
                .description("1:属于自链接"),
                column("    create_user_id      bigint(20)  unsigned        null comment '创建者',"),
                column("    create_time      datetime            default CURRENT_TIMESTAMP not null comment '创建时间',"),
                column("    update_user_id      bigint(20)  unsigned        null comment '更改者',"),
                column("    update_time      datetime            default CURRENT_TIMESTAMP not null comment '更改时间',"),
                column("    del_flag         char(1)             default '0'               null comment '删除标志（0代表存在 1代表删除）'"),
                null
        );

        return table;
    }

    @Override
    public List<TableIndexInfo> tableIndexInfoList() {
        return tableIndexs(
                index("business_link_source_index").indexColumns("source_owner_id, source_owner_name,source_owner_type"),
//                index("business_link_ancestor_index").indexColumns("source_owner_id, source_owner_name"),
                null
        );
    }
//
//    @Override
//    public List<TableTriggerInfo> tableTriggerList() {
//        return tableTriggers(triggerName("inventory_bom_rowstamp")
//                .triggerSql("create trigger inventory_bom_rowstamp before update on inventory_bom FOR EACH ROW\n" +
//                        "begin\n" +
//                        "    set @rowstamp= old.rowstamp;\n" +
//                        "    set NEW.rowstamp=@rowstamp+1;\n" +
//                        "end;\n"));
//    }
}